//
//  ZYCTeachingLearningCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/28.
//

#import "ZYCTeachingLearningCell.h"
#import "ZYCTeachLearningModel.h"

@interface ZYCTeachingLearningCell ()


@property (nonatomic, strong) UIView *bgWhiteView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *line;

//发起者
@property (nonatomic, strong) UILabel *sponsorLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *statusLabel;

@end
@implementation ZYCTeachingLearningCell

- (void)setModel:(ZYCTeachLearningModel *)model{
    _model = model;
    _titleLabel.text = model.evaluateTitle;
    _sponsorLabel.text =  [NSString stringWithFormat:@"发起人:%@",model.createBy];
    _timeLabel.text = [NSString stringWithFormat:@"发布时间:%@",model.createTime];
    NSInteger status = [model.publishStatus integerValue];
    if (status == 1) {
        _statusLabel.text = @"未发布";
        _statusLabel.backgroundColor = HEX_RGB(@"#39A85B");
    }else if(status == 2){
        _statusLabel.text = @"进行中";
        _statusLabel.backgroundColor = HEX_RGB(@"#39A85B");
    }else if(status == 3){
        _statusLabel.text = @"已结束";
        _statusLabel.backgroundColor = HEX_RGB(@"#B9B9B9");
    }
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgWhiteView];
        [self.bgWhiteView addSubview:self.titleLabel];
        [self.bgWhiteView addSubview:self.line];
        [self.bgWhiteView addSubview:self.sponsorLabel];
        [self.bgWhiteView addSubview:self.timeLabel];
        [self.bgWhiteView addSubview:self.statusLabel];

        [self.bgWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(9.5f);
            make.right.equalTo(self.contentView).offset(-9.5f);
            make.top.bottom.equalTo(self.contentView);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.bgWhiteView).offset(10.0f);
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(15.0f);
            make.height.mas_equalTo(1.0f);
        }];
        
        [self.sponsorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.line.mas_bottom).offset(15.0f);
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.sponsorLabel.mas_bottom).offset(15.0f);
            make.bottom.equalTo(self.bgWhiteView).offset(-10.5f);
        }];
        
        [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.line.mas_bottom).offset(13.5f);
            make.size.mas_equalTo(CGSizeMake(56.0f, 23.0f));
        }];

        
    }
    return self;
}


- (UIView *)bgWhiteView {
    if (!_bgWhiteView) {
        _bgWhiteView = [[UIView alloc] init];
        _bgWhiteView.backgroundColor = HEX_RGB(@"#FFFFFF");
        _bgWhiteView.layer.cornerRadius = 7.5;
        _bgWhiteView.layer.masksToBounds = YES;
    }
    return _bgWhiteView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17) titleColor:HEX_RGB(kTitleThemeColor) textAlignment:ZZTextAlignmentLeft];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}

- (UILabel *)sponsorLabel {
    if (!_sponsorLabel) {
        _sponsorLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _sponsorLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _timeLabel;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc] init];
        _statusLabel.font = kCustomFont(@"PingFangSC-Light", 14);
        _statusLabel.textColor = HEX_RGB(@"#FFFFFF");
        _statusLabel.textAlignment = NSTextAlignmentCenter;

        _statusLabel.layer.cornerRadius = 11.5f;
        _statusLabel.layer.masksToBounds = YES;
    }
    return _statusLabel;
}


@end
